<!-- 保证金申请单编辑页面 -->
<template>
	<view>
		<u-form :model="model" :rules="rules" ref="form" labelPosition="top" labelWidth="auto" :labelStyle="{
      	fontSize: '14px',
      	color: '#B2B2B2',
      	lineHight: '20px'
      }">
			<view class="basic-style">
				<view class="basic-title basic-border">基本信息</view>
				<u-form-item label="单据编号" prop="billNo" required>
					<u--input v-model="model.billNo" disabled placeholder="请输入单据编号"></u--input>
				</u-form-item>
				<u-form-item label="申请人" prop="proposer" required>
					<h-select-person-input style="width: 100%" disabled v-model="model.proposer" placeholder="请选择申请人"
						border="surround" suffixIcon="arrow-down-fill" :suffixIconStyle="{ color: '#B2B2B2' }"
						objectField="model.proposer"></h-select-person-input>
				</u-form-item>
				<u-form-item label="申请部门" prop="proposerDeptId" required>
					<h-select-depart-input disabled v-model="model.proposerDeptId" :departName="model.proposerDeptText"
						placeholder="请选择部门" border="surround" style="width: 100%" suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }" :title.sync="model.proposerDeptText"></h-select-depart-input>
				</u-form-item>
				<u-form-item label="申请时间" prop="createTime" required>
					<u--input v-model="model.createTime" disabled></u--input>
				</u-form-item>
				<u-form-item label="申请公司" prop="applicant" required>
					<h-select-company-input style="width: 100%" v-model="model.applicant" border="surround"  
						placeholder="请选择公司" suffixIcon="arrow-down-fill" :suffixIconStyle="{ color: '#B2B2B2' }"
						objectField="model.applicant" @input="resetMetaData"></h-select-company-input>
				</u-form-item>
				<u-form-item label="单据类型" prop="billCategory" required>
					<h-select-input-tag
						class="w-100"
						v-model="model.billCategory"
						disabled
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						placeholder="请选择单据类型"
						border="surround"
						dictName="bill_category"></h-select-input-tag>
				</u-form-item>
				<u-form-item label="费用类型" prop="feeCategory" required>
					<h-select-input-tag
						class="w-100"
						v-model="model.feeCategory"
						disabled
						placeholder="请选择费用类型"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						dictName="fee_category_project"
						@change="resetMetaData"></h-select-input-tag>
				</u-form-item>
				<u-form-item label="项目承接人" prop="projectUndertaker">
					<h-select-person-input disabled v-model="model.projectUndertaker" class="w-100" placeholder="请选择项目承接人"
						searchPlaceholder="请输入" border="surround" suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"></h-select-person-input>
				</u-form-item>
				<u-form-item label="保证金所属团队" prop="teamId">
					<h-select-team-input disabled style="width: 100%" v-model="model.teamId" objectField="model.teamId"
						placeholder="请选择保证金所属团队" border="surround" :tdlx="3"
						@detail="handleTeamChange"></h-select-team-input>
				</u-form-item>
				
				<u-form-item label="关联项目" prop="preProjectId" v-if="model.feeCategory == '2' || model.feeCategory == '4' || model.feeCategory == '5'" required>
						<h-select-project-input
							disabled
							:signUnit="model.applicant"
							v-model="model.preProjectId"
							:costType="model.feeCategory"
							style="width: 100%"
							placeholder="请选择项目名称"
							objectField="model.preProjectId"
							border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
							@input="selectProject"
						></h-select-project-input>
				</u-form-item>
				<u-form-item label="项目编号" prop="projectCode">
					<u--input disabled placeholder="请输入项目编号" v-model="model.projectCode"></u--input>
				</u-form-item>
				<u-form-item label="业绩归属年度" prop="attributionYear">
					<u--input disabled placeholder="请选择业绩归属年度" v-model="model.attributionYear"></u--input>
				</u-form-item>
				<u-form-item label="关联投标档案" prop="tenderId" :required="model.feeCategory == '1' || model.feeCategory == '3'">
						<h-select-omc-project-tender-input
							v-model="model.tenderId"
							objectField="model.tenderId"
							disabled
							style="width: 100%"
							placeholder="请选择关联投标档案"
							border="surround"
							name="projectName"
							:isBid="model.feeCategory=='2' || model.feeCategory == '4' || model.feeCategory == '5' ? 1 : 0"
							:isResult="model.feeCategory=='1' || model.feeCategory == '3'?true:false" 
							:tenderUnit="model.applicant"
							:projectId="model.feeCategory=='1' || model.feeCategory == '3'?'':model.preProjectId"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
							@input="handleTenderChange"
						></h-select-omc-project-tender-input>
				</u-form-item>
			</view>

			<view class="basic-style">
				<view class="basic-title basic-border">打款信息</view>
				<view v-if="model.feeCategory=='2'">
					<u-form-item  label="是否投标转履约" prop="isRelDeposit" required>
						<h-select-input-tag class="w-100" v-model="model.isRelDeposit" objectField="model.isRelDeposit"
							placeholder="请选择是否投标转履约" border="surround" dictName="yes_or_no" suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"  @input="handleIsRelDeposit"></h-select-input-tag>
					</u-form-item>
					<u-form-item label="关联投标保证金" prop="relDepositBill" required v-show="model.feeCategory=='2' && model.isRelDeposit=='1'">
						<h-select-finance-deposit-bill-input
							:disabled="!model.preProjectId"
							v-model="model.relDepositBill"
							:projectId="model.preProjectId"
							:feeCategory="'1'"
							objectField="model.relDepositBill"
							style="width: 100%;"
							placeholder="请选择关联投标保证金"
							@input="relBillData"
							border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
						></h-select-finance-deposit-bill-input>
					</u-form-item>
				</view>
				<u-form-item label="原投标保证金金额(元)" prop="originPaymentAmount" v-show="model.feeCategory=='2' && model.isRelDeposit=='1'">
					<u--input v-model="model.originPaymentAmount" disabled placeholder="请输入原投标保证金金额"></u--input>
				</u-form-item>
				<u-form-item label="汇款单位名称" prop="remittanceUnit" required>
					<h-select-company-input disabled v-model="model.remittanceUnit" placeholder="请选择汇款单位"
						border="surround" style="width: 100%" suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"></h-select-company-input>
				</u-form-item>
				<u-form-item label="汇款截止时间" prop="remittanceEndTime" required>
					<h-time-select mode="date" ref="remittanceEndTime" v-model="model.remittanceEndTime" disabled
						placeholder="请选择汇款截止时间" border="surround" suffixIcon="calendar-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"></h-time-select>
				</u-form-item>
				<u-form-item label="汇款账户要求" prop="remittanceAccountRequirements" required>
					<h-select-input-tag
						class="w-100"
						v-model="model.remittanceAccountRequirements"
						placeholder="请选择汇款账户要求"
						border="surround"
						disabled
						dictName="remittance_account_requirements"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"></h-select-input-tag>
				</u-form-item>
				<u-form-item label="汇款方式" prop="remittanceMode" required>
					<!-- <h-select-input-tag class="w-100" v-model="model.remittanceMode" objectField="model.remittanceMode"
						placeholder="请选择汇款方式" border="surround" dictName="remittance_mode" disabled
						@change="radioModeChange"></h-select-input-tag> -->
						<h-select-input-tag
							class="w-100"
							v-model="model.remittanceMode"
							objectField="model.remittanceMode"
							disabled
							placeholder="请选择汇款方式" border="surround" dictName="remittance_mode" suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
							@change="radioModeChange"></h-select-input-tag>
				</u-form-item>
				<template v-if="model.feeCategory=='3' || model.feeCategory=='4' || model.feeCategory=='5'">
					<u-form-item label="保函金额(元)" prop="letterAmount" required>
						<u--input placeholder="请输入保函金额" type="number" disabled v-model="model.letterAmount"></u--input>
					</u-form-item>
				</template>
				<u-form-item label="保证金金额(元)" prop="remittanceAmount" required>
					<u--input placeholder="请输入保证金金额" disabled type="number" v-model="model.remittanceAmount" @change="countCurrentAmount"></u--input>
				</u-form-item>
				<!-- 			<u-form-item label="归还金额（元）" prop="unreturnAmount" required>
					<u--input type="number" v-number-normal placeholder="请输入归还金额"
						v-model="model.unreturnAmount"></u--input>
				</u-form-item> -->
				<u-form-item label="本次支付金额(元)" prop="currentPaymentAmount">
					<u--input placeholder="请输入本次支付金额" v-model="model.currentPaymentAmount" disabled></u--input>
				</u-form-item>
				<u-form-item label="收款单位名称" prop="payeeUnit" required>
					<u--input v-model="model.payeeUnit" disabled placeholder="请输入收款单位名称"></u--input>
				</u-form-item>
				<template v-if="model.remittanceMode == '2'">
					<u-form-item label="收款方银联号" prop="cnapsCode" required>
						<h-select-finance-kingdee-bank-input-popup
							class="w-100"
							suffixIcon="arrow-down-fill"
							disabled
							:suffixIconStyle="{color: '#B2B2B2'}"
							v-model="model.cnapsCode"
							placeholder="请选择收款方银联号"
							@change="backCnapsCode" />
					</u-form-item>
					<u-form-item label="收款方开户行" prop="payeeBankName" required>
						<u--input v-model="model.payeeBankName" disabled placeholder="请输入收款方开户行"></u--input>
					</u-form-item>
					<u-form-item label="收款方账户" prop="payeeAccountNo" required>
						<u--input v-model="model.payeeAccountNo" disabled placeholder="请输入收款方账户"></u--input>
					</u-form-item>
					<u-form-item label="收款联系人" prop="payeeContacts">
						<u--input v-model="model.payeeContacts" disabled placeholder="请输入收款联系人"></u--input>
					</u-form-item>
					<u-form-item label="收款联系方式" prop="payeeContactInfo">
						<u--input v-model="model.payeeContactInfo" disabled placeholder="请输入收款联系方式"></u--input>
					</u-form-item>
				</template>
				<u-form-item label="预计返款时间" prop="estimateRefundTime">
					<h-time-select mode="date" ref="estimateRefundTime" v-model="model.estimateRefundTime"
						placeholder="请选择预计返款时间" disabled border="surround" suffixIcon="calendar-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"></h-time-select>
				</u-form-item>
				<u-form-item label="打款附言" prop="postscript">
					<!-- #ifdef H5 -->
					<u--textarea v-model="model.postscript" confirm-type="done" maxlength="500" count placeholder="请输入打款附言"></u--textarea>
					<!-- #endif -->
					<!-- #ifndef H5 -->
					<u--textarea v-model="model.postscript" :confirm-type="null" maxlength="500" count placeholder="请输入打款附言"></u--textarea>
					<!-- #endif -->
				</u-form-item>
				<u-form-item label="情况说明" prop="remark" required>
					<!-- #ifdef H5 -->
					<u--textarea v-model="model.remark" disabled confirm-type="done" maxlength="500" count placeholder="请输入情况说明"></u--textarea>
					<!-- #endif -->
					<!-- #ifndef H5 -->
					<u--textarea v-model="model.remark" disabled :confirm-type="null" maxlength="500" count placeholder="请输入情况说明"></u--textarea>
					<!-- #endif -->
				</u-form-item>
			</view>

			<view class="basic-style">
				<view class="basic-title basic-border">附件信息</view>
				<view class="py-1 space-y-1" style="width: 100%">
					<file-list v-if="model.attachments" v-model="model.attachments"></file-list>
				</view>
			</view>
		  <view class="space-x-1 px-1 btn_position">
		  	<backButton  @onSubmit="onSubmit" :nodeObj="nodeObj" :model="dataForm" :resultObj="resultObj"></backButton>
		  </view>
			<view style="height: 100rpx;"></view>
		</u-form>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import moment from 'moment'
	import http from '@/utils/request/index'
	import backButton from '@/components/backButton.vue'
	import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
	import {
		getProcessTaskTransInfo, // 流程流转
	} from '@/api/index.js'
	import {
		gainBillNo,
		add,
		edit,
		info,
		queryResultByTenderId
	} from '@/api/finance/ErpFinanceProjectDepositBillForm'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
	export default {
		name: 'ErpFinanceProjectDepositBillForm',
		components: {
			fileList,
			backButton
		},
		data() {
			return {
				resultObj: {}, // 流程图流转信息
				dataForm: {},
				nodeObj: {},
				tabvalue: '',
				
				isSubmit: false,
				backUpApplicant: '',
				backUpTeamId: '',
				index: null,
				id: '',
				dictOptions: {},
				model: {
					// 基本信息 - 公用
					bpmBizTitle: '',
					billNo: '',
					proposer: '',
					proposerDeptId: '',
					createTime: '',
					applicant: '',
					// 基本信息 - 非公用
					teamId: '',
					postscript: '', // 大款附言
					remark: '',
					billCategory: '',
					feeCategory: '',
					// tenderNo: '',
					tenderId: '',
					preProjectId: '',
					projectUndertaker: '',
					remittanceUnit: '',
					remittanceEndTime: '',
					remittanceAccountRequirements: '',
					remittanceMode: '',
					remittanceAmount: '',
					unreturnAmount: '',
					payeeUnit: '',
					payeeBankName: '',
					payeeAccountNo: '',
					payeeContacts: '',
					payeeContactInfo: '',
					estimateRefundTime: '',
					// 附件
					attachments: null,
				},
				formData: [],
				rules: {
					billNo: [{
						required: true,
						message: '请输入单据编号!',
						trigger: ['blur', 'change']
					}],
					proposerDeptId: [{
						required: true,
						message: '请选择申请部门!',
						trigger: ['blur', 'change']
					}],
					proposer: [{
						required: true,
						message: '请选择申请人!',
						trigger: ['blur', 'change']
					}],
					createTime: [{
						required: true,
						message: '请选择申请时间!',
						trigger: ['blur', 'change']
					}],
					// bpmBizTitle: [{ required: true, message: '请输入流程标题!' }],
					applicant: [{
						required: true,
						message: '请输入申请公司!',
						trigger: ['blur', 'change']
					}],
					billCategory: [{
						required: true,
						message: '请选择单据类型!',
						trigger: ['blur', 'change']
					}],
					tenderId: [{
						required: true,
						message: '请选择关联投标档案!',
						trigger: ['blur', 'change']
					}],
					preProjectId: [{
						required: true,
						message: '请选择关联项目!',
						trigger: ['blur', 'change']
					}],
					remittanceUnit: [{
						required: true,
						message: '请选择汇款单位!',
						trigger: ['blur', 'change']
					}],
					remittanceEndTime: [{
						required: true,
						message: '请选择汇款截止时间!',
						trigger: ['blur', 'change']
					}],
					// feeCategory: [{
					// 	required: true,
					// 	message: '请选择费用类型!',
					// 	trigger: ['blur', 'change']
					// }],
					remittanceAccountRequirements: [{
						required: true,
						message: '请输入汇款账户要求!',
						trigger: ['blur', 'change']
					}],
					remittanceMode: [{
						required: true,
						message: '请输入汇款方式!',
						trigger: ['blur', 'change']
					}],
					// remittanceAmount: [{
					// 	required: true,
					// 	pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/,
					// 	message: '请输入保证金金额!',
					// 	trigger: ['blur', 'change']
					// }, ],
					// payeeUnit: [{
					// 	required: true,
					// 	message: '请输入收款单位名称!',
					// 	trigger: ['blur', 'change']
					// }],
					// payeeBankName: [{
					// 	required: true,
					// 	message: '请输入收款方开户行!',
					// 	trigger: ['blur', 'change']
					// }],
					// isRelDeposit: [
					// 	{ required: true, message: '请选择是否投标转履约!', trigger: ['blur', 'change'] }
					// ],
					// relDepositBill: [
					// 	{ required: true, message: '请选择关联的投标保证金!', trigger: ['blur', 'change'] }
					// ],
					// cnapsCode: [
					// 	{ required: true, message: '请选择收款方银联号!', trigger: ['blur', 'change'] }
					// ],
					// letterAmount: [
					// 	{ required: true, type: 'number', pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入保函金额!', trigger: ['blur', 'change'] }
					// ],
					payeeAccountNo: [{
						required: true,
						message: '请输入银行账户!',
						trigger: ['blur', 'change']
					}],
					remark: [{
						required: true,
						message: '请输入情况说明!',
						trigger: ['blur', 'change']
					}],
					payeeContactInfo: [{
							required: false,
							message: '请输入联系方式!'
						},
						{
							pattern: /^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/,
							message: '请输入正确的联系方式!',
							trigger: ['blur', 'change']
						},
					],
				},
				flowCode: 'onl_erp_finance_project_deposit_bill',
				formUrl: "/erp/finance/deposit/modules/ErpFinanceProjectDepositBillForm",
				formUrlMobile: "/pages/synergy/erpFinanceProjectDepositBillList",
				processId:"1521678235605229569",
				beanName:"erpFinanceProjectDepositBillServiceImpl"
			}
		},
		onLoad(options) {
		  this.dataForm = JSON.parse(decodeURIComponent(options.item))
			this.initDictConfig()
		  var that = this
			var eventChannel
		  // #ifdef APP-NVUE
		  eventChannel = this.$scope.eventChannel // 兼容APP-NVUE
		  // #endif
		  // #ifndef APP-NVUE
		  eventChannel = this.getOpenerEventChannel()
		  // #endif
		  // 监听sendMessage事件，获取上一页面通过eventChannel传送到当前页面的数据
		  eventChannel.on('sendMessage', function (data) {
				that.nodeObj = JSON.parse(decodeURIComponent(data.nodeObj))
				that.id = that.nodeObj.dataId
		    that.tabvalue = data.tabvalue
		    that.initInfo()
				that.getProcessTaskTrans(that.dataForm.id)
				
		  })
		},
		computed: {
			...mapState(['userInfo']),
		},
		methods: {
			initDictConfig() {
				initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
					if (res.success) {
						this.$set(this.dictOptions, 'teamManager', res.result)
					}
				})
			},
			// 选择是否投标转履约
			handleIsRelDeposit(){
				if(this.model.isRelDeposit==='0'){
					this.$set(this.model, 'relDepositBill', null);
					this.$set(this.model, 'originPaymentAmount', null);
				}
			},
			relBillData(data) {
				if(data) {
					// 保证金
					this.$set(this.model, 'remittanceMode', data.remittanceMode || ''); // 汇款方式
					this.$set(this.model, 'originPaymentAmount', data.remittanceAmount || ''); // 归还总额
					this.$set(this.model, 'payeeUnit', data.payeeUnit || ''); // 银行金额
					this.$set(this.model, 'payeeAccountNo', data.payeeAccountNo || ''); // 账号
					this.$set(this.model, 'payeeBankName', data.payeeBankName || ''); // 收款单位
					this.$set(this.model, 'cnapsCode', data.cnapsCode || ''); // 联行号
					this.$set(this.model, 'payeeContactInfo', data.payeeContactInfo || ''); // 联行号
					this.$set(this.model, 'payeeContacts', data.payeeContacts || ''); // 联行号
					this.countCurrentAmount();
				}
			},
			// 收款方银联号
			backCnapsCode(data){
				if(data){
					this.$set(this.model, 'payeeBankName', data.bankBranchName)
				}
			},
			// 修改保证金金额事件触发
			countCurrentAmount(){
				if(this.model.remittanceAmount && this.model.originPaymentAmount ){
					let amount=(this.model.remittanceAmount-this.model.originPaymentAmount).toFixed(2)
					if(amount>0){
						this.$set(this.model, 'currentPaymentAmount', amount);
					}else{
						this.$set(this.model, 'currentPaymentAmount', 0);
					}
				}else if(this.model.remittanceAmount){
					this.$set(this.model, 'currentPaymentAmount', this.model.remittanceAmount);
				}else{
					this.$set(this.model, 'currentPaymentAmount', 0);
				}
			},
			// 查询流程流转信息 -- 获取下一节点信息
			getProcessTaskTrans(taskId){
				getProcessTaskTransInfo({ taskId }).then(res => {
					if(res.success){
						this.resultObj = res.result
					} else {
						this.$refs.uToast.show({
							message: res.message,
							type: 'error'
						})
					}
				}).catch(err => {
					console.log(err);
				})
			},
			
			radioModeChange(val) {
				if (val === '2' && this.model.payeeUnit) {
					// nothing to do
				} else {
					this.$set(this.model, 'payeeBankName', '');
					this.$set(this.model, 'cnapsCode', '');
					this.$set(this.model, 'payeeAccountNo', '');
					this.$set(this.model, 'payeeContacts', '');
					this.$set(this.model, 'payeeContactInfo', '');
				}
			},
			resetMetaData() {
				this.$set(this.model, 'preProjectId', '');
				this.$set(this.model, 'tenderId', '');
				this.$set(this.model, 'projectUndertaker', '');
				this.$set(this.model,'projectCode', '');
				this.$set(this.model, 'teamId', '');
				this.$set(this.model, 'attributionYear', '');
				this.$set(this.model, 'remittanceAmount', 0);
				// 由项目自动带出的信息也清空（收款单位名称、收款方开户行、收款方账户）
				this.$set(this.model, 'payeeUnit', '')
				this.$set(this.model, 'payeeAccountNo', '')
				this.$set(this.model, 'cnapsCode', '');
				this.$set(this.model, 'payeeBankName', '')
				this.$set(this.model, 'remittanceUnit', this.model.applicant  || '');
				// if (this.model.feeCategory == '1' || this.model.feeCategory == '3' ) {
				// 	this.$set(this.rules, 'tenderId', [{
				// 		required: true,
				// 		message: '请选择关联投标档案!',
				// 		trigger: ['blur', 'change']
				// 	}]);
				// } else if (this.model.feeCategory == '2' || this.model.feeCategory == '4' || this.model.feeCategory == '5') {
				// 	this.$set(this.rules, 'tenderId', [{
				// 		required: false,
				// 		message: '请选择关联投标档案!',
				// 		trigger: ['blur', 'change']
				// 	}]);
				// }
				// if(this.model.feeCategory=='1' || this.model.feeCategory == '2' ){
				// 	this.$set(this.rules,'remittanceAmount',[
				// 		{ required: true, pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入保证金金额!', trigger: ['blur', 'change'] }
				// 	])
				// }else{
				// 	this.$set(this.rules,'remittanceAmount',[
				// 		{ required: true, pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入保证金金额!', trigger: ['blur', 'change'] }
				// 	])
				// }
				if(this.model.isRelDeposit){
					this.$set(this.model, 'isRelDeposit', '')
					this.$set(this.model, 'relDepositBill', '')
					this.$set(this.model, 'originPaymentAmount', '')
				}
			},
			
			// 关联项目
			selectProject(data){
				this.$set(this.model, 'projectCode', data?.finalNo || '')
				this.$set(this.model, 'attributionYear', data?.year || '')
				if(data){
					this.$set(this.model, 'tenderId', '');
					this.$set(this.model,'projectUndertaker',data.undertaker)
					this.$set(this.model,'teamId',data.teamName)
					//投标保证金
					if (this.model.feeCategory == '1'|| this.model.feeCategory == '3' ) {
						http.get('/api/erp/omc/tender/erpOmcTenderFinal/queryTenderDataByProjectId', {projectId:data.id}).then((res) => {
							if (res.success) {
								let data = res.result.records || res.result
								if(data.length>0){
									// 保证金金额
									this.$set(this.model, 'remittanceAmount', data[0].tenderBond);
									// 收款单位名称
									//迭代11 单据中打款信息-收款单位名称、收款方开户行、收款方账户字段改为非带入，人工填写。
									// this.$set(this.model, 'payeeUnit', data[0].ownerUnit)
									// 如果带出了收款单位名称且汇款方式为转账且收款信息没有就带出(此操作为了防止单子填完修改费用类型时收款信息带不出)
									// if(this.model.payeeUnit&&this.model.remittanceMode
									//   &&this.model.remittanceMode==2
									//   &&!this.model.payeeBankName&&!this.model.payeeAccountNo){
									//     // 调用切换为转账的方法主动触发反写收款信息
									//     this.radioModeChange(this.model.remittanceMode)
									// }
									// 调用切换为转账的方法主动触发反写收款信息
									this.radioModeChange(this.model.remittanceMode)
									this.countCurrentAmount();
								}else{
									this.$set(this.model, 'remittanceAmount', 0);
									this.countCurrentAmount();
								}
					
							}
						})
					// 履约保证金
					}else if (this.model.feeCategory == '2'|| this.model.feeCategory == '4' || this.model.feeCategory == '5' ) {
						if(this.model.relDepositBill){
							this.$set(this.model, 'isRelDeposit', null)
							this.$set(this.model, 'relDepositBill', null)
							this.$set(this.model, 'originPaymentAmount', null)
						}
						http.get('/api/erp/omc/tender/erpOmcTenderResultFinal/queryTenderResultDataByProjectId', {projectId:data.id}).then((res) => {
							if (res.success) {
								let data = res.result.records || res.result || ''
								// 保证金金额
								this.$set(this.model, 'remittanceAmount', data.bail);
								// 收款单位名称
								//   this.$set(this.model, 'payeeUnit', data.ownerUnit);
									// 如果带出了收款单位名称且汇款方式为转账且收款信息没有就带出(此操作为了防止单子填完修改费用类型时收款信息带不出)
									// if(this.model.payeeUnit&&this.model.remittanceMode
									//   &&this.model.remittanceMode==2
									//   &&!this.model.payeeBankName&&!this.model.payeeAccountNo){
									//     // 调用切换为转账的方法主动触发反写收款信息
									//     this.radioModeChange(this.model.remittanceMode)
									// }
									// 调用切换为转账的方法主动触发反写收款信息
									this.radioModeChange(this.model.remittanceMode)
									this.countCurrentAmount();
							}
						})
					}
				}else{
					this.$set(this.model,'attributionYear',null)
					this.$set(this.model,'projectUndertaker',null)
					this.$set(this.model,'teamId',null)
					this.$set(this.model, 'isRelDeposit', null)
					this.$set(this.model, 'relDepositBill', null)
					this.$set(this.model, 'originPaymentAmount', null)
					this.$set(this.model, 'remittanceAmount', 0);
					this.$set(this.model, 'tenderId', null);
					this.countCurrentAmount();
				}
			},
			
			handleTenderChange(data) {
				if (((this.model.feeCategory == '1' || this.model.feeCategory == '3')  && data) || ((this.model.feeCategory == '2' || this.model.feeCategory == '4' || this.model.feeCategory == '5'  )&& data.choseObj == undefined)) {
					if (data.id) {
						this.$set(this.model, 'preProjectId', data.prepareProjectId)
						// this.$set(this.model, 'remittanceAmount', data.tenderBond);
						this.$set(this.model, 'projectUndertaker', data.undertaker)
						this.$set(this.model, 'teamId', data.businessTeam)
						if (this.model.feeCategory == '2' || this.model.feeCategory == '4' || this.model.feeCategory == '5') {
							queryResultByTenderId({
									tenderId: data.id
								})
								.then((res) => {
									let resa = res.result
									if (resa) {
										this.$set(this.model, 'remittanceAmount', res.result.bail)
									} else {
										this.$set(this.model, 'remittanceAmount', 0)
									}
									this.countCurrentAmount();
								})
								.catch((e) => {
									console.log(e)
								})
						} else {
							this.$set(this.model, 'remittanceAmount', data.tenderBond)
							this.countCurrentAmount();
						}
						if (this.model.feeCategory == '1' || this.model.feeCategory == '3') {
							http.get('/api/erp/omc/project/erpOmcProject/queryById', {id:data.prepareProjectId}).then((ress) => {
								if (ress.success) {
									let data = ress.result
									this.$set(this.model, 'attributionYear', data.year);
									this.$set(this.model, 'projectCode', data.finalNo);
								}
							})
						} else {
							this.$set(this.model, 'remittanceAmount', data.tenderBond);
							this.countCurrentAmount();
						}
					} else if (this.model.feeCategory=='1' || this.model.feeCategory == '3') {
						this.$set(this.model, 'preProjectId', '');
						this.$set(this.model, 'remittanceAmount', 0);
						this.$set(this.model,'projectUndertaker','')
						this.$set(this.model,'teamId','')
						this.countCurrentAmount();
					}
				} else if(this.model.feeCategory=='2' || this.model.feeCategory == '4' || this.model.feeCategory == '5'){
					http.get('/api/erp/omc/tender/erpOmcTenderResultFinal/queryTenderResultDataByProjectId', {projectId:this.model.preProjectId}).then((res) => {
						if (res.success) {
							let data = res.result.records || res.result
							// 保证金金额
							this.$set(this.model, 'remittanceAmount', data.bail);
							// 收款单位名称
							this.radioModeChange(this.model.remittanceMode)
							this.countCurrentAmount();
						}
					})
					http.get('/api/erp/omc/project/erpOmcProject/queryById', {id:this.model.preProjectId}).then((res) => {
						if (res.success) {
							let data = res.result.records || res.result
							this.$set(this.model,'projectUndertaker',data.undertaker)
							this.$set(this.model,'teamId',data.teamName)
						}
					})
				} else {
					this.$set(this.model, 'preProjectId', '');
					this.$set(this.model, 'remittanceAmount', 0);
					this.$set(this.model,'projectUndertaker','')
					this.$set(this.model,'teamId','')
					this.countCurrentAmount();
				}
			},
			// 获取单据编号
			async initBillNo() {
				const res = await gainBillNo({
					proposer: this.userInfo.empId
				})
				this.model.billNo = res.result
				this.model.bpmBizTitle = this.userInfo?.employee?.name + '-' + this.model.billNo //标题
			},
			// 初始化新增需要的数据
			initForm() {
				this.model.proposer = this.userInfo.empId //当前登录人
				this.model.proposerDeptId = this.userInfo.deptId //当前登录人部门
				this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss')
			},
			async initInfo() {
				const response = await info({
					id: this.id
				})
				const data = response?.result || {}
				this.model = Object.assign({}, data)
				if(this.model.feeCategory == '1' || this.model.feeCategory == '3'){
					this.$set(this.rules, 'tenderId', [{
						required: true,
						message: '请选择关联投标档案!',
						trigger: ['blur', 'change']
					}]);
				} else if (this.model.feeCategory == '2'|| this.model.feeCategory == '4' || this.model.feeCategory == '5' ) {
					this.$set(this.rules, 'tenderId', [{
						required: false,
						message: '请选择关联投标档案!',
						trigger: ['blur', 'change']
					}]);
				}
				if(this.model.feeCategory=='1' || this.model.feeCategory == '2' ){
					this.$set(this.rules,'remittanceAmount',[
						{ required: true, pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入保证金金额!', trigger: ['blur', 'change'] }
					])
				}else{
					this.$set(this.rules,'remittanceAmount',[
						{ required: true, pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入保证金金额!', trigger: ['blur', 'change'] }
					])
				}
			},
			validateForm() {
				return this.$refs.form.validate()
			},
			handleTeamChange(item) {
				this.model.teamYear = item.tdnd
			},
			
			getCreateTime() {
			  let createTime = this.model.createTime
			  let date = createTime.substring(0, 10)
			  return date.substring(0, 4) + '年' + date.substring(5, 7) + '月' + date.substring(8, 10) + '日'
			},
			setBpmBizTitle() {
				var that = this
				// 标题 表单名称+项目名称+发起人+申请日期
				let createTime = this.getCreateTime()
				let teamName = filterMultiDictText(this.dictOptions['teamManager'], that.model.teamId + '')
				that.model.bpmBizTitle = (teamName? teamName+ ' - ':'') + this.userInfo?.employee?.name + ' - ' + createTime + (that.model.remittanceAmount? ' - ' + that.model.remittanceAmount :'') //标题
			},
			checkContractId() {
				// 有没有带出收款合同
				if (!this.model.contractId) {
					this.$u.toast('该项目还未签收款合同!')
					return
				}
			},
			async onSubmit() {
				await this.validateForm()
				try {
					var url = ''
					if (this.id) {
						url = edit
					} else {
						url = add
					}
					var _this = this
					this.$set(this.model, 'unreturnAmount', this.model.remittanceAmount);
					const response = await url({
						...this.model,
						// slipDetailList: this.formData,
					})
					if (response.success) {
					  this.$refs.uToast.show({
					  	message: '提交成功',
					  	type: 'success',
					  	complete () {
					  		_this.onAudit()
					  	}
					  })
					  this.isSubmit = true
					} else {
					  this.$refs.uToast.show({
					    message: response.message,
					    type: 'error',
					  })
					}
				} finally {
					// this.loading = false
				}
			},
			
			onAudit() {
			  if (!this.isSubmit) {
			    uni.showToast({
			      title: '请完善表单后审核',
			      icon: 'none',
			    })
			    return false
			  }
			  var that = this
			  uni.navigateTo({
			    url: '/pages/synergy/erpFinanceProjectDepositBillList' + `?item=${encodeURIComponent(JSON.stringify(this.dataForm).replace(/%/g, '%25'))}`,
			    events: {
			      // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
			      // acceptDataFromOpenedPage: function(data) {
			      // }
			    },
			    success: function (data) {
			      // 通过eventChannel向被打开页面传送数据
			      var params = {
			        nodeObj: encodeURIComponent(JSON.stringify(that.nodeObj).replace(/%/g, '%25')),
			        tabvalue: that.tabvalue,
			      }
			      data.eventChannel.emit('sendMessage', params)
			    },
			    fail: function (err) {
			      this.$refs.uToast.show({
			        message: '请联系管理员配置',
			        type: 'error',
			      })
			    },
			  })
			}
		},
		watch: {
			'model.applicant'(current, old) {
				if (old && current && old !== current) {
					this.backUpApplicant = old
					// this.resetMetaData()
				}
			},
			'model.teamId'(current, old) {
				if (old && current && old !== current) {
					this.backUpTeamId = old
					// this.resetMetaData()
				}
			},
		},
	}
</script>

<style scoped lang="scss">
	@import url('@/assets/inputStyle.scss');
	.trip-form-data {
		::v-deep {
			.u-form-item__body {
				padding-top: 2px;
				padding-bottom: 2px;
			}
		}
	}

	.checkbox-item {
		display: flex;
		align-items: center;
	}
</style>